﻿#region Copyright(c) 2006 ZO, All right reserved.
// -----------------------------------------------------------------------------
// Copyright(c) 2006 ZO, All right reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//   1.  Redistribution of source code must retain the above copyright notice,
//       this list of conditions and the following disclaimer.
//   2.  Redistribution in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//   3.  The name of the author may not be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// -----------------------------------------------------------------------------
#endregion


#region Using directives

using System;
using System.ComponentModel;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;

#endregion

namespace ZO.SmartCore.Windows.Forms
{
    /// <summary>
    /// Represents a window or dialog box that can be used as a Main Form.
    /// </summary>
	[ToolboxBitmap(typeof(Form))]
	[ToolboxItem(false)]
	public class SmartMainForm : SmartForm
    {

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="SmartMainForm"/> class.
        /// </summary>
        public SmartMainForm()
            : this(false)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SmartMainForm"/> class.
        /// </summary>
        /// <param name="dropShadow">if set to <see langword="true"/> [dropshadow].</param>
        public SmartMainForm(bool dropShadow)
            : base(dropShadow)
        {
            this.InitializeComponent();

        }
        #endregion

        #region Destructor

        #endregion

        #region Fields

        #endregion

        #region Delegates
        private delegate void LoadModulesDelegate();

        #endregion


        #region Events

        /// <summary>
        /// Occurs When Loading of all modules started.
        /// </summary>
        /// <remarks>
        /// This event is used by the spalsh screen to notify splash scrrent that form is started loading modules.
        /// </remarks>
        public event EventHandler ModuleLoadingStarted;


        /// <summary>
        /// Fires for each module load.
        /// </summary>
        public event EventHandler<ModuleEventArgs> LoadingModule;


        /// <summary>
        /// Occurs When all Module are Loaded Completed.
        /// </summary>
        /// <remarks>
        /// This event is used by the spalsh screen to notify splash scrrent that all modules are loaded completed.
        /// </remarks>
        public event EventHandler ModuleLoadingCompleted;
        #endregion

        #region Operators

        #endregion

        #region Properties

        #endregion

        #region Methods


        /// <summary>
        /// Initializes the component.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // SmartForm
            // 
            this.ClientSize = new Size(292, 266);
            this.Name = "SmartForm";
            this.ResumeLayout(false);

        }

        /// <summary>
        /// Raises the <see cref="LoadingModule"/> event.
        /// </summary>
        protected virtual void OnLoadingModule(string name)
        {
            if (LoadingModule != null)
            {
                this.LoadingModule(this, new ModuleEventArgs(name));
            }
        }

        /// <summary>
        /// Raises the <see cref="ModuleLoadingStarted"/> event.
        /// </summary>
        protected virtual void OnModuleLoadingStarted()
        {
            if (ModuleLoadingStarted != null)
            {
                this.ModuleLoadingStarted(this, EventArgs.Empty);
            }
        }

        /// <summary>
        /// Raises the <see cref="ModuleLoadingCompleted"/> event.
        /// </summary>
        protected virtual void OnModuleLoadingCompleted()
        {

            if (ModuleLoadingCompleted != null)
            {
                this.ModuleLoadingCompleted(this, EventArgs.Empty);
            }
        }


        /// <summary>
        /// Loads the modules in background Thread.
        /// </summary>
        /// <remarks>Use The Invoke method to call method in proper thread</remarks>
        protected virtual void LoadModules()
        {
            this.BeginInvoke((ThreadStart)delegate { this.OnModuleLoadingCompleted(); }); 


        }



        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.Load"></see> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"></see> that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            this.OnModuleLoadingStarted();

            LoadModulesDelegate del = new LoadModulesDelegate(this.LoadModules);

            del.BeginInvoke(null, null);

            base.OnLoad(e);

        }



        #endregion

    }
}
